import axios from '@/utils/request'

export default {
  OfficerBond: {
    entity: { name: 'Bond', prefix: `officer` },
    list: {
      query: {
        '@expands': '["entity.staff"]'
      },
      disabled_actions: ['lines'],
      list_filter: {
        name: {
          expression: `entity.getStaff().getName() matches ":value" || entity.getStaff().getUser().getUsername() matches ":value"`,
          label: '员工名/电话',
          type: 'input'
        },
        staffId: {
          expression: `entity.getStaff().getId() == ":value"`,
          label: '员工id',
          type: 'input'
        }
      },
      list_display: [
        'id',
        'staff',
        { property: 'staff.__metadata.user.__toString', label: '用户' },
        { property: 'fee', label: '保证金', editable: true },
        { property: 'payable', label: '欠款' },
        { property: 'balance', label: '保证金户余额' },
        'comment'
      ]
    },
    form: {
      fields: [
        {
          property: 'staff',
          component: {
            props: ['form', 'property'],
            data() {
              return { data: [] }
            },
            created() {
              axios.get(`/officer/staffs`, {
                params: {
                  'limit': 1000000
                }
              }).then((res) => {
                this.data = res.data
              })
            },
            render(h) {
              return (
                <el-select v-model={this.form[this.property]} clearable filterable>{
                  Object.assign(this.data).map(v => {
                    return <el-option key={v.id} label={v.name + '(' + v.phone + ')'} value={v.id} />
                  })
                }</el-select>
              )
            }
          }
        },
        { property: 'fee', field_options: { label: '保证金' }},
        { property: 'comment', type: 'textarea' }
      ]
    }
  }
}

